Sigil (computer Programming)
   HOME

TheInfoList



OR:

In
computer programming Computer programming is the process of performing a particular computation (or more generally, accomplishing a specific computing result), usually by designing and building an executable computer program. Programming involves tasks such as ana ...
, a sigil () is a symbol affixed to a
variable Variable may refer to: * Variable (computer science), a symbolic name associated with a value and whose associated value may be changed * Variable (mathematics), a symbol that represents a quantity in a mathematical expression, as used in many ...
name, showing the variable's datatype or
scope Scope or scopes may refer to: People with the surname * Jamie Scope (born 1986), English footballer * John T. Scopes (1900–1970), central figure in the Scopes Trial regarding the teaching of evolution Arts, media, and entertainment * Cinem ...
, usually a prefix, as in $foo, where $ is the sigil. ''
Sigil A sigil () is a type of symbol used in magic. The term has usually referred to a pictorial signature of a deity or spirit. In modern usage, especially in the context of chaos magic, sigil refers to a symbolic representation of the practitioner ...
'', from the
Latin Latin (, or , ) is a classical language belonging to the Italic branch of the Indo-European languages. Latin was originally a dialect spoken in the lower Tiber area (then known as Latium) around present-day Rome, but through the power of the ...
'' sigillum'', meaning a "little sign", means ''a sign or image supposedly having magical power''. Sigils can be used to separate and demarcate
namespace In computing, a namespace is a set of signs (''names'') that are used to identify and refer to objects of various kinds. A namespace ensures that all of a given set of objects have unique names so that they can be easily identified. Namespaces ...
s that possess different properties or behaviors.


Historical context

The use of sigils was popularized by the
BASIC programming language BASIC (Beginners' All-purpose Symbolic Instruction Code) is a family of General-purpose programming language, general-purpose, high-level programming languages designed for ease of use. Dartmouth BASIC, The original version was created by John ...
. The best known example of a sigil in BASIC is the
dollar sign The dollar sign, also known as peso sign, is a symbol consisting of a capital " S" crossed with one or two vertical strokes ($ or ), used to indicate the unit of various currencies around the world, including most currencies denominated "pes ...
("$") appended to the names of all strings. Many BASIC dialects use other sigils (like "%") to denote
integer An integer is the number zero (), a positive natural number (, , , etc.) or a negative integer with a minus sign (−1, −2, −3, etc.). The negative numbers are the additive inverses of the corresponding positive numbers. In the language ...
s and
floating point number In computing, floating-point arithmetic (FP) is arithmetic that represents real numbers approximately, using an integer with a fixed precision, called the significand, scaled by an integer exponent of a fixed base. For example, 12.345 can be r ...
s and their precision, and sometimes other types as well.
Larry Wall Larry Arnold Wall (born September 27, 1954) is an American computer programmer and author. He created the Perl programming language. Personal life Wall grew up in Los Angeles and then Bremerton, Washington, before starting higher education at ...
adopted
shell script A shell script is a computer program designed to be run by a Unix shell, a command-line interpreter. The various dialects of shell scripts are considered to be scripting languages. Typical operations performed by shell scripts include file manip ...
ing's use of sigils for his Perl programming language. In Perl, the sigils do not specify fine-grained data-types like strings and integers, but the more general categories of scalars (using a prefixed "$"), arrays (using "@"), hashes (using "%"), and
subroutine In computer programming, a function or subroutine is a sequence of program instructions that performs a specific task, packaged as a unit. This unit can then be used in programs wherever that particular task should be performed. Functions may ...
s (using "&"). Raku also uses secondary sigils, or twigils, to indicate the scope of variables. Prominent examples of twigils in Raku include "^", used with self-declared formal parameters ("placeholder variables"), and ".", used with object attribute accessors (i.e., instance variables). In
CLIPS CLIPS is a public domain software tool for building expert systems. The name is an acronym for "C Language Integrated Production System." The syntax and name were inspired by Charles Forgy's OPS5. The first versions of CLIPS were developed st ...
, scalar variables are prefixed with a "?" sigil while multifield (e.g., a 1-level list) variables are prefixed with "$?". In
Common Lisp Common Lisp (CL) is a dialect of the Lisp programming language, published in ANSI standard document ''ANSI INCITS 226-1994 (S20018)'' (formerly ''X3.226-1994 (R1999)''). The Common Lisp HyperSpec, a hyperlinked HTML version, has been derived fro ...
, special variables (with dynamic scope) are typically surrounded with * in what is dubbed the "
earmuff convention Common Lisp (CL) is a dialect of the Lisp programming language, published in ANSI standard document ''ANSI INCITS 226-1994 (S20018)'' (formerly ''X3.226-1994 (R1999)''). The Common Lisp HyperSpec, a hyperlinked HTML version, has been derived fro ...
". While this is only convention, and not enforced, the language itself adopts the practice (e.g., *standard-output*). Similarly, some programmers surround constants with +. In
CycL CycL in computer science and artificial intelligence is an ontology language used by Doug Lenat's Cyc artificial intelligence project. Ramanathan V. Guha was instrumental in the design of early versions of the language. There is a close varian ...
, variables are prefixed with a "?" sigil. Similarly, constant names are prefixed with "#$" (pronounced "hash-dollar"). In
Elixir ELIXIR (the European life-sciences Infrastructure for biological Information) is an initiative that will allow life science laboratories across Europe to share and store their research data as part of an organised network. Its goal is to bring t ...
, sigils are provided via the "~" symbol, followed by a letter to denote the type of sigil, and then delimiters. For example ~r(foo) is a regular expression of "foo". Other sigils include ~s for strings and ~D for dates. Programmers can also create their own sigils. In the
esoteric Western esotericism, also known as esotericism, esoterism, and sometimes the Western mystery tradition, is a term scholars use to categorise a wide range of loosely related ideas and movements that developed within Western society. These ideas a ...
INTERCAL The Compiler Language With No Pronounceable Acronym (INTERCAL) is an esoteric programming language that was created as a parody by Don Woods and , two Princeton University students, in 1972. It satirizes aspects of the various programming langu ...
, variables are a 16-bit integer identifier prefixed with either "." (called "spot") for 16-bit values, ":" (called "twospot") for 32-bit values, "," ("tail") for arrays of 16-bit values and ";" ("hybrid") for arrays of 32-bit values. The later CLC-Intercal added "@" ("whirlpool") for a variable that can contain no value (used for classes) and "_" used to store a modified
compiler In computing, a compiler is a computer program that translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primarily used for programs that ...
. In
MAPPER MAPPER, now known as BIS, is a fourth-generation programming language from Sperry Univac. Mapper originated in the 1970s based on some work in the 1960s, but has been kept current. It was renamed and also given an extension named ICE - Internet ...
(aka BIS), named variables are prefixed with "<" and suffixed with ">" because strings or character values do not require quotes. In mIRC script, identifiers have a "$" sigil, while all variables have a "%" prefixed (regardless of local or global variables or data type). Binary variables are prefixed by an "&". In the
MUMPS MUMPS ("Massachusetts General Hospital Utility Multi-Programming System"), or M, is an imperative, high-level programming language with an integrated transaction processing key–value database. It was originally developed at Massachusetts Gener ...
programming language, "$" precedes intrinsic function names and 'special variable names' (built-in variables for accessing the execution state). "$Z" precedes non-standard intrinsic function names. "$$" precedes extrinsic function names. Routines (used for procedures, subroutines, functions) and global variables (database storage) are prefixed by a caret (^). The last global variable subtree may be referenced indirectly by a caret and the last subscript; this is referred to as a "naked reference". System-wide routines and global variables (stored in certain shared database(s)) are prefixed with ^%; these are referred to as "percent routines" and "percent globals". In
Objective-C Objective-C is a general-purpose, object-oriented programming language that adds Smalltalk-style messaging to the C programming language. Originally developed by Brad Cox and Tom Love in the early 1980s, it was selected by NeXT for its NeXTS ...
, string literals preceded with "@" are instances of the object type NSString or, since
clang Clang is a compiler front end for the C, C++, Objective-C, and Objective-C++ programming languages, as well as the OpenMP, OpenCL, RenderScript, CUDA, and HIP frameworks. It acts as a drop-in replacement for the GNU Compiler Collection (GCC), ...
v3.1 /
LLVM LLVM is a set of compiler and toolchain technologies that can be used to develop a front end for any programming language and a back end for any instruction set architecture. LLVM is designed around a language-independent intermediate represen ...
v4.0, NSNumber, NSArray or NSDictionary. The prefix-@ is also used on the keywords interface, implementation, and end to express the structure of class definitions. Within class declarations and definitions as well, a prefix of - is used to indicate member methods and variables, while prefix + indicates class elements. In the
PHP PHP is a general-purpose scripting language geared toward web development. It was originally created by Danish-Canadian programmer Rasmus Lerdorf in 1993 and released in 1995. The PHP reference implementation is now produced by The PHP Group. ...
language, which was largely inspired by Perl, "$" precedes any
variable Variable may refer to: * Variable (computer science), a symbolic name associated with a value and whose associated value may be changed * Variable (mathematics), a symbol that represents a quantity in a mathematical expression, as used in many ...
name. Names not prefixed by this are considered constants,
function Function or functionality may refer to: Computing * Function key, a type of key on computer keyboards * Function model, a structured representation of processes in a system * Function object or functor or functionoid, a concept of object-oriente ...
s or
class Class or The Class may refer to: Common uses not otherwise categorized * Class (biology), a taxonomic rank * Class (knowledge representation), a collection of individuals or objects * Class (philosophy), an analytical concept used differentl ...
names (or interface or trait names, which share the same namespace as classes).
PILOT An aircraft pilot or aviator is a person who controls the flight of an aircraft by operating its directional flight controls. Some other aircrew members, such as navigators or flight engineers, are also considered aviators, because they a ...
uses "$" for buffers (string variables), "#" for integer variables, and "*" for program labels.
Python Python may refer to: Snakes * Pythonidae, a family of nonvenomous snakes found in Africa, Asia, and Australia ** ''Python'' (genus), a genus of Pythonidae found in Africa and Asia * Python (mythology), a mythical serpent Computing * Python (pro ...
uses a "@" prefix, called ''pie syntax'', for application of decorators and a "__" prefix, called ''dunder'', for "private" attributes. In
Ruby A ruby is a pinkish red to blood-red colored gemstone, a variety of the mineral corundum ( aluminium oxide). Ruby is one of the most popular traditional jewelry gems and is very durable. Other varieties of gem-quality corundum are called sa ...
, ordinary variables lack sigils, but "$" is prefixed to
global variable In computer programming, a global variable is a variable with global scope, meaning that it is visible (hence accessible) throughout the program, unless shadowed. The set of all global variables is known as the ''global environment'' or ''global s ...
s, "@" is prefixed to
instance variable In class-based, object-oriented programming, an instance variable is a variable defined in a class (i.e. a member variable), for which each instantiated object of the class has a separate copy, or instance. An instance variable has similarities ...
s, and "@@" is prefixed to
class variable In class-based, object-oriented programming, a class variable is a variable defined in a class of which a single copy exists, regardless of how many instances of the class exist. A class variable is not an instance variable. It is a special typ ...
s. Ruby also uses (strictly conventional) suffix sigils: "?" indicates a predicate method returning (usually) a boolean value; and "!" indicates that the method may have a potentially unexpected effect, and needs to be handled with care. In
Scheme A scheme is a systematic plan for the implementation of a certain idea. Scheme or schemer may refer to: Arts and entertainment * ''The Scheme'' (TV series), a BBC Scotland documentary series * The Scheme (band), an English pop band * ''The Schem ...
, by convention, the names of procedures that always return a boolean value usually end in "?". Likewise, the names of procedures that store values into parts of previously allocated Scheme objects (such as pairs, vectors, or strings) usually end in "!".
Standard ML Standard ML (SML) is a general-purpose, modular, functional programming language with compile-time type checking and type inference. It is popular among compiler writers and programming language researchers, as well as in the development of the ...
uses the prefix sigil "'" on a variable that refers to a type. If the sigil is doubled, it refers to a type for which equality is defined. The "'" character may also appear within or at the end of a variable, in which case it has no special meaning. In
Transact-SQL Transact-SQL (T-SQL) is Microsoft's and Sybase's proprietary extension to the SQL (Structured Query Language) used to interact with relational databases. T-SQL expands on the SQL standard to include procedural programming, local variables, vari ...
, "@" precedes a local variable or parameter name. System variables (known as global variables) are distinguished by a "@@" prefix. In
Windows PowerShell PowerShell is a task automation and configuration management program from Microsoft, consisting of a command-line shell and the associated scripting language. Initially a Windows component only, known as Windows PowerShell, it was made open-so ...
, which was partly inspired by
Unix shell A Unix shell is a command-line Interpreter (computing), interpreter or shell (computing), shell that provides a command line user interface for Unix-like operating systems. The shell is both an interactive command language and a scripting langua ...
s and Perl, variable names are prefixed by the "$" sigil. In
XSLT XSLT (Extensible Stylesheet Language Transformations) is a language originally designed for transforming XML documents into other XML documents, or other formats such as HTML for web pages, plain text or XSL Formatting Objects, which may subseque ...
, variables and parameters have a leading "$" sigil on use, although when defined in <xsl:param> or <xsl:variable> with the "name" attribute, the sigil is not included. Related to XSLT,
XQuery XQuery (XML Query) is a query and functional programming language that queries and transforms collections of structured and unstructured data, usually in the form of XML, text and with vendor-specific extensions for other data formats (JSON, bin ...
uses the "$" sigil form both in definition and in use. In
MEL Mel, Mels or MEL may refer to: Biology * Mouse erythroleukemia cell line (MEL) * National Herbarium of Victoria, a herbarium with the Index Herbariorum code MEL People * Mel (given name), the abbreviated version of several given names (including ...
, variable names are prefixed by "$" to distinguish them from functions, commands, and other identifiers.


Similar phenomena


Shell scripting variables

In Unix
shell scripting A shell script is a computer program designed to be run by a Unix shell, a command-line interpreter. The various dialects of shell scripts are considered to be scripting languages. Typical operations performed by shell scripts include file manip ...
and in utilities such as
Makefile In software development, Make is a build automation tool that automatically builds executable programs and libraries from source code by reading files called ''Makefiles'' which specify how to derive the target program. Though integrated develo ...
s, the "$" is a unary operator that translates the name of a variable into its contents. While this may seem similar to a sigil, it is properly a
unary operator In mathematics, an unary operation is an operation with only one operand, i.e. a single input. This is in contrast to binary operations, which use two operands. An example is any function , where is a set. The function is a unary operation on ...
for lexical
indirection In computer programming, indirection (also called dereferencing) is the ability to reference something using a name, reference, or container instead of the value itself. The most common form of indirection is the act of manipulating a value throug ...
, similar to the *
dereference operator In computer programming, the dereference operator or indirection operator, sometimes denoted by "*" (i.e. an asterisk), is a unary operator (i.e. one with a single operand) found in C-like languages that include pointer variables. It operates ...
for pointers in C, as noticeable from the fact that the dollar sign is omitted when assigning to a variable.


Identifier conventions

In Fortran, sigils are not used, but all variables starting with the letters I, J, K, L, M and N are
integers An integer is the number zero (), a positive natural number (, , , etc.) or a negative integer with a minus sign (−1, −2, −3, etc.). The negative numbers are the additive inverses of the corresponding positive numbers. In the language o ...
by default. Fortran documentation refers to this as "implicit typing". Explicit typing is also available to allow any variable to be declared with any type. Various programming languages including
Prolog Prolog is a logic programming language associated with artificial intelligence and computational linguistics. Prolog has its roots in first-order logic, a formal logic, and unlike many other programming languages, Prolog is intended primarily ...
,
Haskell Haskell () is a general-purpose, statically-typed, purely functional programming language with type inference and lazy evaluation. Designed for teaching, research and industrial applications, Haskell has pioneered a number of programming lan ...
,
Ruby A ruby is a pinkish red to blood-red colored gemstone, a variety of the mineral corundum ( aluminium oxide). Ruby is one of the most popular traditional jewelry gems and is very durable. Other varieties of gem-quality corundum are called sa ...
and Go treat
identifier An identifier is a name that identifies (that is, labels the identity of) either a unique object or a unique ''class'' of objects, where the "object" or class may be an idea, physical countable object (or class thereof), or physical noncountable ...
s beginning with a capital letter differently from identifiers beginning with a small letter, a practice related to the use of sigils.


Stropping

Actually a form of stropping, the use of many languages in Microsoft's .NET Common Language Infrastructure (CLI) requires a way to use variables in a different language that may be keywords in a calling language. This is sometimes done by prefixes. In C#, any variable names may be prefixed with "@". This is mainly used to allow the use of variable names that would otherwise conflict with keywords. The same is achieved in
VB.Net Visual Basic, originally called Visual Basic .NET (VB.NET), is a multi-paradigm, object-oriented programming language, implemented on .NET, Mono, and the .NET Framework. Microsoft launched VB.NET in 2002 as the successor to its original Visua ...
by enclosing the name in square brackets, as in nd/code>. The "@" prefix can also be applied to string literals; see literal affixes below.


Hungarian notation

Related to sigils is
Hungarian notation Hungarian notation is an identifier naming convention in computer programming, in which the name of a variable or function indicates its intention or kind, and in some dialects its type. The original Hungarian notation uses intention or kind in it ...
, a
naming convention A naming convention is a convention (generally agreed scheme) for naming things. Conventions differ in their intents, which may include to: * Allow useful information to be deduced from the names based on regularities. For instance, in Manhatta ...
for variables that specifies variable type by attaching certain alphabetic prefixes to the variable name. Unlike sigils, however, Hungarian notation provides no information to the compiler; as such, explicit types must be redundantly specified for the variables (unless using a language with
type inference Type inference refers to the automatic detection of the type of an expression in a formal language. These include programming languages and mathematical type systems, but also natural languages in some branches of computer science and linguistics ...
). As most standard compilers do not enforce use of the prefixes, this permits omission and also makes code prone to confusion due to accidental erroneous use.Linux kernel coding style
by Linus Torvalds


Literal affixes

While sigils are applied to names (identifiers), similar prefixes and suffixes can be applied to literals, notably
integer literal In computer science, an integer literal is a kind of literal for an integer whose value is directly represented in source code. For example, in the assignment statement x = 1, the string 1 is an integer literal indicating the value 1, while in the ...
s and
string literal A string literal (computer programming), literal or anonymous string is a String (computer science), string value in the source code of a computer program. Modern Computer programming, programming languages commonly use a quoted sequence of charact ...
s, specifying either how the literal should be evaluated, or what data type it is. For example, 0x10ULL evaluates to the value 16 as an unsigned long long integer in C++: the 0x prefix indicates hexadecimal, while the suffix ULL indicates unsigned long long. Similarly, prefixes are often used to indicate a
raw string A string literal or anonymous string is a string value in the source code of a computer program. Modern programming languages commonly use a quoted sequence of characters, formally " bracketed delimiters", as in x = "foo", where "foo" is a strin ...
, such as r"C:\Windows" in Python, which represents the string with value C:\Windows; as an escaped string this would be written as "C:\\Windows". As this affects the semantics (value) of a literal, rather than the syntax or semantics of an identifier (name), this is neither stropping (identifier syntax) nor a sigil (identifier semantics), but it is syntactically similar.


Java annotations

Compare
Java annotation In the Java computer programming language, an annotation is a form of syntactic metadata that can be added to Java source code. Classes, methods, variables, parameters and Java packages may be annotated. Like Javadoc tags, Java annotations can ...
s such as @Override and @Deprecated.


Confusion

In some cases the same syntax can be used for distinct purposes, which can cause confusion. For example, in C#, the "@" prefix can be used either for stropping (to allow reserved words to be used as identifiers), or as a prefix to a literal (to indicate a
raw string A string literal or anonymous string is a string value in the source code of a computer program. Modern programming languages commonly use a quoted sequence of characters, formally " bracketed delimiters", as in x = "foo", where "foo" is a strin ...
); in this case neither use is a sigil, as it affects the syntax of identifiers or the semantics of literals, not the semantics of identifiers.


See also

* Delimiter *
Source code In computing, source code, or simply code, is any collection of code, with or without comments, written using a human-readable programming language, usually as plain text. The source code of a program is specially designed to facilitate the wo ...
* Token


References

{{DEFAULTSORT:Sigil (Computer Programming) Source code Variable (computer science) Naming conventions